package io.github.i678.bukkitantipmc.utils;

import io.github.i678.bukkitantipmc.AntiFakePMC;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Chat and console utilities file.
 * @author TheNameMan
 * @since Dev build 9
 */
public class ChatUtils extends AntiFakePMC {
	
	public static void logMessage(Level level, String msg) {
		
		Logger logger = Bukkit.getServer().getLogger();
		
		logger.log(level, msg);
		
	}
	
	public static void broadcast(String m, String p) {
		for(Player player : Bukkit.getOnlinePlayers()) {
			if(p == null) {
				player.sendMessage(m);
			} else {
				if(player.hasPermission(p)) {
					player.sendMessage(m);
				}
			}
		}
	}

    public static void broadcast(String msg) {
        if(notify.equalsIgnoreCase("permissions")) {
            for(Player pl : Bukkit.getOnlinePlayers()) {
                if(pl.hasPermission("antipmc.notify")) {
                    pl.sendMessage(msg);
                }
            }
        } else if(notify.equalsIgnoreCase("global")) {
            for(Player pl : Bukkit.getOnlinePlayers()) {
                pl.sendMessage(msg);
            }
        } else if(notify.equalsIgnoreCase("console")) {
            logMessage(Level.INFO, msg);
        } else if(notify.equalsIgnoreCase("op")) {
            for(Player p : Bukkit.getOnlinePlayers()) {
                if(p.isOp()) {
                    p.sendMessage(msg);
                }
            }
        }
    }
	
	public static void help(Player sender) {
		sender.sendMessage(ChatColor.GOLD + "------------- [Your AntiFakePMC Commands] --------------");

		sender.sendMessage(ChatColor.GREEN + "/antipmc help [command]");

		if(sender.hasPermission("antipmc.use.modify.notify")) {
			sender.sendMessage(ChatColor.GREEN + "/antipmc notify <global|permissions|console|off>");
		}

		if(sender.hasPermission("antipmc.use.version")) {
			sender.sendMessage(ChatColor.GREEN + "/antipmc version");
		}

		sender.sendMessage(ChatColor.GOLD + "------------- [Your AntiFakePMC Commands] --------------");
	}

}
